import request from "@/util/request";
import type {
    Sku,Spu,
    GoodsCreateDTO,
    SpuCategoryVO,
    SpuCategory,
    SkuAttributeGroup,
    SkuAttribute,
    AttributeAndValuesDTO,
    GroupAttributeValuesDTO,SkuModifyDTO,AttributeAssociatedVO
} from '@/api/serve/re-market/type'
import type {PageType} from "@/api/type";

enum API {
    SKU_BASE = "/serve/re-market/sku",
    SKU_PAGE = "/serve/re-market/sku/page",
    SKU_ATTR_GROUP = "/serve/re-market/sku/attribute/group",
    SKU_ATTR_GROUP_BY_CATEGORY_ID = "/serve/re-market/sku/attribute/group/by/category",
    SKU_ATTR_GROUP_PAGE = "/serve/re-market/sku/attribute/group/page",
    SKU_GROUP_ATTRIBUTE_VALUES = "/serve/re-market/sku/attribute/group/attribute/value/by/category",
    SKU_ATTRIBUTE = "/serve/re-market/sku/attribute",
    SKU_MODIFY_DTO = "/serve/re-market/sku/modify-dto",
    SKU_SALE_ATTRIBUTE_BY_CATEGORY_ID = "/serve/re-market/sku/attribute/sale/by/category",
    SKU_ATTRIBUTE_PAGE = "/serve/re-market/sku/attribute/page",
    SKU_ATTRIBUTE_PAGE_BY_GROUP = "/serve/re-market/sku/attribute/page/by-group",
    ATTR_GROUP_ASSOCIATED = "/serve/re-market/sku/attribute/group/associated",
    SPU_BASE = "/serve/re-market/spu",
    SPU_CATEGORY = "/serve/re-market/spu-category",
    SPU_CATEGORY_TREE_LIST = "/serve/re-market/spu-category/tree-list",
    SPU_PAGE = "/serve/re-market/spu/page",
}

export const reqGetSkuPage = (params: any) => {
    return request<PageType<Sku>>({
        url: API.SKU_PAGE,
        method: "get",
        params
    })
}
export const reqGetSkuById = (id: string) => {
    return request<Sku>({
        url: API.SKU_PAGE + "/" + id,
        method: "get",
    })
}
export const reqCreateGoods = (data: GoodsCreateDTO) => {
    return request({
        url: API.SKU_BASE,
        method: "post",
        data
    })
}
export const reqGetSkuModifyDto = (id: string |number) => {
    return request<SkuModifyDTO>({
        url: API.SKU_MODIFY_DTO + "/" + id,
        method: "get",
    })
}
export const reqUpdateSku = (data: SkuModifyDTO) => {
    return request({
        url: API.SKU_BASE,
        method: "put",
        data
    })
}
export const reqDeleteSku = (id: string) => {
    return request({
        url: API.SKU_BASE + "/" + id,
        method: "delete",
    })
}

export function reqGetSpuCategoryTreeList() {
    return request<SpuCategoryVO[]>({
        url: API.SPU_CATEGORY_TREE_LIST,
        method: "get",
    })
}
export function reqGetSpuPage(query: any) {
    return request({
        url: API.SPU_PAGE,
        method: "get",
        params: query,
    })
}
export function reqGetSpuById(id: string) {
    return request<Spu>({
        url: API.SPU_BASE + "/" + id,
        method: "get",
    })
}
export function reqDeleteSpuCategory(id: number) {
    return request({
        url: API.SPU_CATEGORY + "/" + id,
        method: "delete",
    })
}
export function reqModifySpu(data: Spu){
    return request({
        url: API.SPU_BASE,
        method: "put",
        data
    })
}
export function reqAddSpuCategory(data: SpuCategory) {
    return request({
        url: API.SPU_CATEGORY,
        method: "post",
        data
    })
}

export function reqUpdateSpuCategory(data: SpuCategory) {
    return request({
        url: API.SPU_CATEGORY,
        method: "put",
        data
    })
}

export function reqCreateSkuAttrGroup(data: SkuAttributeGroup) {
    return request({
        url: API.SKU_ATTR_GROUP,
        method: "post",
        data
    })
}

export function reqUpdateSkuAttrGroup(data: SkuAttributeGroup) {
    return request({
        url: API.SKU_ATTR_GROUP,
        method: "put",
        data
    })
}

export function reqDeleteSkuAttrGroup(groupId: number) {
    return request({
        url: API.SKU_ATTR_GROUP + "/" + groupId,
        method: "delete",
    })
}

export function reqGetSkuAttrGroupById(id: number) {
    return request<SkuAttributeGroup>({
        url: API.SKU_ATTR_GROUP + "/" + id,
        method: "get",
    })
}

export function reqGetSkuAttrGroupListByCategoryId(categoryId: number) {
    return request<SkuAttributeGroup[]>({
        url: API.SKU_ATTR_GROUP_BY_CATEGORY_ID + "/" + categoryId,
        method: "get",
    })
}

export function reqGetSkuGroupAttributeValuesByCategoryId(categoryId: number |string) {
    return request<GroupAttributeValuesDTO[]>({
        url: API.SKU_GROUP_ATTRIBUTE_VALUES + "/" + categoryId,
        method: "get",
    })
}

export function reqGetSkuAttrGroupPage(params: any) {
    return request<PageType<SkuAttributeGroup>>({
        url: API.SKU_ATTR_GROUP_PAGE,
        method: "get",
        params
    })
}

export function reqCreateSkuAttribute(data: SkuAttribute) {
    return request({
        url: API.SKU_ATTRIBUTE,
        method: "post",
        data
    })
}

export function reqGetSkuSaleAttributeListByCategoryId(categoryId: number | string) {
    return request<AttributeAndValuesDTO[]>({
        url: API.SKU_SALE_ATTRIBUTE_BY_CATEGORY_ID + "/" + categoryId,
        method: "get",
    })
}

export function reqUpdateSkuAttribute(data: SkuAttribute) {
    return request({
        url: API.SKU_ATTRIBUTE,
        method: "put",
        data
    })
}

export function reqDeleteSkuAttribute(id: number) {
    return request({
        url: API.SKU_ATTRIBUTE + "/" + id,
        method: "delete",
    })
}

export function reqGetSkuAttributeById(id: number) {
    return request<SkuAttribute>({
        url: API.SKU_ATTRIBUTE + "/" + id,
        method: "get",
    })
}

export function reqGetSkuAttributePage(params: any) {
    return request<PageType<SkuAttribute>>({
        url: API.SKU_ATTRIBUTE_PAGE,
        method: "get",
        params
    })
}
export function reqGetSkuAttributePageByGroup(params: any) {
    return request<PageType<AttributeAssociatedVO>>({
        url: API.SKU_ATTRIBUTE_PAGE_BY_GROUP,
        method: "get",
        params
    })
}

export function reqSkuAttributeGroupAssociated(data) {
    return request({
        url: API.ATTR_GROUP_ASSOCIATED,
        method: "post",
        data
    })
}
